package net.pimpas.web.jsf.components.validators.operation;

import javax.faces.context.FacesContext;

import net.pimpas.resourcebundle.serviceprovider.ResourceBundleServiceProviderType;
import net.pimpas.web.jsf.components.validators.PimpasValidator;
import net.pimpas.web.jsf.components.validators.PimpasValidatorTag;
import net.pimpas.web.jsf.components.validators.exception.PimpasValidatorTagException;

public class OperationValidatorTag extends PimpasValidatorTag<OperationValidator> {

	private static final long serialVersionUID = 1L;
	private String operation;

	@Override
	public String getValidatorID() {
		return OperationValidator.VALIDATOR_ID;
	}
	
	@Override
	protected void validate(FacesContext context, OperationValidator validator) throws PimpasValidatorTagException {
		// check clazz
		if(this.getOperation() == null || "".equals(this.getOperation()))
			try {
				throw new PimpasValidatorTagException(this.getBundle().getMessage(PimpasValidator.class, "propertyNull", ResourceBundleServiceProviderType.ERROR, "operation", this.getId()));
			} catch (Throwable e) {
				throw new PimpasValidatorTagException(e);
			}
			
			validator.setOperation(this.getOperation());
	}

	public String getOperation() {
		return operation;
	}

	public void setOperation(String operation) {
		this.operation = operation;
	}
}